<template>
  <el-row class="d-flex flex-column" v-if="$route.path === '/info/subsidy-info'">
    <el-col :span="24">
      <form class="el-form query-form el-form--label-right el-form--inline">
        <div class="el-form-item el-form-item--medium" v-if="admin.mType < 5">
          <label for="date" class="el-form-item__label" style="width: 60px;">村</label>
          <div class="el-form-item__content">
            <el-cascader
              v-model="query.villageWrap"
              :options="townToVillage"
              change-on-select
              @change="selectTownOrVillage"
              :clearable="admin.mType != 4"
            ></el-cascader>
          </div>
        </div>
        <!-- <div class="el-form-item el-form-item--medium">
          <label for="date" class="el-form-item__label" style="width: 80px;">补助项</label>
          <div class="el-form-item__content">
            <el-select v-model="query.type" clearable placeholder="补助项">
              <el-option
                v-for="item in typeAtt"
                :key="item.value"
                :label="item.ST_Name"
                :value="item.SubsidyType_Id"
              ></el-option>
            </el-select>
          </div>
        </div>-->
        <div class="el-form-item el-form-item--medium">
          <label for="date" class="el-form-item__label" style="width: 80px;">补助群体</label>
          <div class="el-form-item__content">
            <el-select v-model="query.qType" clearable @change="typeChange">
              <el-option
                v-for="item in [
                {
                  label: '补助对象',
                  value: 1,
                },
                {
                  label: '补助户',
                  value: 0,
                },
                ]"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </div>
        </div>
        <div class="el-form-item el-form-item--medium">
          <label for="date" class="el-form-item__label" style="width: 80px;">关键字</label>
          <div class="el-form-item__content">
            <el-input placeholder="请输入内容" v-model="query.name" clearable></el-input>
          </div>
        </div>
        <div class="el-form-item el-form-item--medium ml-6">
          <div class="el-form-item__content">
            <el-button type="primary" icon="el-icon-search" @click="to_query">搜索</el-button>
          </div>
        </div>
        <div class="el-form-item el-form-item--medium ml-9" v-if="!(admin.mType == 3)">
          <div class="el-form-item__content">
            <el-button plain icon="el-icon-plus" @click="show_form()">
              <span>添加</span>
            </el-button>
          </div>
        </div>
      </form>
    </el-col>
    <el-col :span="24">
      <el-table
        v-loading="loading"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(225, 225, 225, 0.8)"
        ref="multipleTable"
        :data="items"
        border
        tooltip-effect="dark"
        max-height="600"
        style="width: 100%"
        @selection-change="handleSelectionChange"
        v-show="this.query.qType == 1"
      >
        <el-table-column type="selection" width="100" align="center"></el-table-column>
        <el-table-column label="序号" type="index" width="80" fixed align="center"></el-table-column>
        <el-table-column label="补助项" width="240" align="center" fixed prop="subsidyname.sName"></el-table-column>
        <el-table-column label="补助对象名字" width="200" align="center" prop="soName"></el-table-column>
        <el-table-column label="所属村" width="200" align="center" prop="village.vName"></el-table-column>
        <el-table-column label="身份证号" width="200" align="center" prop="soShenfenzheng"></el-table-column>
        <el-table-column label="补助金额" width="240" align="center" prop="soBeiyong2"></el-table-column>
        <el-table-column label="补助原因" width="240" align="center" prop="soBeiyong4"></el-table-column>
        <el-table-column label="补助年份" width="140" align="center" prop="soBeiyong5"></el-table-column>
        <el-table-column label="编辑" align="center" fixed="right" width="300">
          <template slot-scope="scope" v-if="$route.path === '/info/subsidy-info'">
            <el-button
              v-if="!(admin.mType == 3)"
              type="warning"
              icon="el-icon-edit"
              @click="updataObject(scope.$index)"
            >编辑</el-button>
            <el-button
              v-if="!(admin.mType == 3)"
              type="danger"
              icon="el-icon-delete"
              @click="delHouse(scope.row.subsidyobjectId, scope.row['soName'])"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-table
        v-loading="loading"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(225, 225, 225, 0.8)"
        ref="multipleTable"
        :data="items"
        border
        tooltip-effect="dark"
        max-height="600"
        style="width: 100%"
        @selection-change="handleSelectionChange"
        v-show="this.query.qType != 1"
      >
        <el-table-column type="selection" width="100" align="center"></el-table-column>
        <el-table-column label="序号" type="index" width="80" fixed align="center"></el-table-column>
        <el-table-column label="补助项" width="240" align="center" fixed prop="subsidyname.sName"></el-table-column>
        <el-table-column label="补助户名字" width="200" align="center" prop="shName"></el-table-column>
        <el-table-column label="所属村" width="200" align="center" prop="village.vName"></el-table-column>
        <el-table-column label="身份证号" width="200" align="center" prop="shBeiyong2"></el-table-column>
        <el-table-column label="补助金额" width="240" align="center" prop="shBeiyong3"></el-table-column>
        <el-table-column label="补助原因" width="240" align="center" prop="shFamilyinformation"></el-table-column>
        <el-table-column label="补助年份" width="140" align="center" prop="shHu"></el-table-column>
        <el-table-column label="编辑" align="center" fixed="right" width="350">
          <template slot-scope="scope" v-if="$route.path === '/info/subsidy-info'">
            <el-button
              v-if="!(admin.mType == 3)"
              type="warning"
              icon="el-icon-edit"
              @click="updataHouse(scope.$index)"
            >编辑</el-button>
            <el-button
              v-if="!(admin.mType == 3)"
              type="danger"
              icon="el-icon-delete"
              @click="delHouse(scope.row.subsidizedhouseholdsId, scope.row['shName'])"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div style="margin-top: 20px">
        <el-row>
          <el-col :span="12">
            <div
              class="grid-content bg-purple d-flex jc-between ai-center"
              v-if="!(admin.mType == 3)"
            >
              <el-button
                type="primary"
                icon="el-icon-delete"
                style="display: block;"
                class="h-1 w-1"
                @click="del_multip('S_name')"
              ></el-button>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple-light">
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pagination.current_page"
                :page-sizes="pagination.page_sizes"
                :page-size="pagination.page_size"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pagination.total"
              ></el-pagination>
            </div>
          </el-col>
        </el-row>
      </div>
    </el-col>
    <el-dialog
      title="新增补助信息"
      v-if="$route.path === '/info/subsidy-info'"
      width="35%"
      :show-close="false"
      :close-on-click-modal="false"
      :lock-scroll="true"
      :visible.sync="dialogFormVisible_create"
    >
      <el-form ref="form" :model="objectForm" label-width="7.1rem" class="d-flex flex-column w-10">
        <el-col :span="24">
          <el-tabs type="border-card" @tab-click="change_create">
            <el-tab-pane label="补助对象信息添加">
              <el-col :span="24" class="d-flex flex-column">
                <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                  <label for="date" class="el-form-item__label" style="width: 7.1rem;">村</label>
                  <div class="el-form-item__content">
                    <el-cascader
                      v-model="objectForm.soVillageidWrap"
                      :options="townToVillage"
                      :show-all-levels="false"
                      @change="get_typeAtt"
                      :disabled="this.admin.mType == 5"
                    ></el-cascader>
                  </div>
                </div>
                <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                  <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助项</label>
                  <div class="el-form-item__content">
                    <el-select v-model="objectForm.soEnjoythesubsidy" placeholder="请选择">
                      <el-option
                        v-for="item in createTypeAtt"
                        :key="item.S_Key"
                        :label="item.S_name"
                        :value="item.S_Key"
                      ></el-option>
                    </el-select>
                  </div>
                </div>
                <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                  <label for="date" class="el-form-item__label" style="width: 7.1rem;">对象名字</label>
                  <div class="el-form-item__content">
                    <el-input v-model="objectForm.soName" placeholder="请输入内容"></el-input>
                  </div>
                </div>
                <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                  <label for="date" class="el-form-item__label" style="width: 7.1rem;">性别</label>
                  <div class="el-form-item__content">
                    <el-select v-model="objectForm.soBeiyong1" placeholder="请选择">
                      <el-option v-for="item in ['男', '女']" :key="item" :label="item" :value="item"></el-option>
                    </el-select>
                  </div>
                </div>
                <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                  <label for="date" class="el-form-item__label" style="width: 7.1rem;">身份证号</label>
                  <div class="el-form-item__content">
                    <el-input v-model="objectForm.soShenfenzheng" placeholder="请输入内容"></el-input>
                  </div>
                </div>
                <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                  <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助年份</label>
                  <div class="el-form-item__content">
                    <el-date-picker
                      v-model="objectForm.soBeiyong5"
                      format="yyyy"
                      value-format="yyyy"
                      type="year"
                      placeholder="选择日期"
                    ></el-date-picker>
                  </div>
                </div>
                <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                  <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助金额</label>
                  <div class="el-form-item__content">
                    <el-input v-model="objectForm.soBeiyong2" placeholder="请输入内容"></el-input>
                  </div>
                </div>
              </el-col>
              <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助原因</label>
                <div class="el-form-item__content">
                  <el-input v-model="objectForm.soBeiyong4" type="textarea" :rows="5" clearable></el-input>
                </div>
              </div>
            </el-tab-pane>
            <el-tab-pane label="补助家庭信息添加">
              <el-col :span="24">
                <el-col :span="24" class="d-flex flex-column">
                  <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                    <label for="date" class="el-form-item__label" style="width: 7.1rem;">村</label>
                    <div class="el-form-item__content">
                      <el-cascader
                        v-model="houseForm.SH_VillageidWrap"
                        :options="townToVillage"
                        :show-all-levels="false"
                        @change="get_typeAtt"
                        :disabled="this.admin.mType == 5"
                      ></el-cascader>
                    </div>
                  </div>
                  <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                    <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助项</label>
                    <div class="el-form-item__content">
                      <el-select v-model="houseForm.shEnjoythesubsidy" placeholder="请选择">
                        <el-option
                          v-for="item in createTypeAtt"
                          :key="item.S_Key"
                          :label="item.S_name"
                          :value="item.S_Key"
                        ></el-option>
                      </el-select>
                    </div>
                  </div>
                  <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                    <label for="date" class="el-form-item__label" style="width: 7.1rem;">家庭代表人姓名</label>
                    <div class="el-form-item__content">
                      <el-input v-model="houseForm.shName" placeholder="请输入内容"></el-input>
                    </div>
                  </div>
                  <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                    <label for="date" class="el-form-item__label" style="width: 7.1rem;">代表人身份证号</label>
                    <div class="el-form-item__content">
                      <el-input v-model="houseForm.shBeiyong2" placeholder="请输入内容"></el-input>
                    </div>
                  </div>
                  <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                    <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助年份</label>
                    <div class="el-form-item__content">
                      <el-date-picker
                        v-model="houseForm.shHu"
                        format="yyyy"
                        value-format="yyyy"
                        type="year"
                        placeholder="选择日期"
                      ></el-date-picker>
                    </div>
                  </div>
                  <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                    <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助金额</label>
                    <div class="el-form-item__content">
                      <el-input v-model="houseForm.shBeiyong3" placeholder="请输入内容"></el-input>
                    </div>
                  </div>
                </el-col>
                <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                  <label for="date" class="el-form-item__label" style="width: 7.1rem;">家庭地址</label>
                  <div class="el-form-item__content">
                    <el-input v-model="houseForm.shAddress" clearable></el-input>
                  </div>
                </div>
                <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
                  <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助原因</label>
                  <div class="el-form-item__content">
                    <el-input
                      v-model="houseForm.shFamilyinformation"
                      type="textarea"
                      :rows="5"
                      clearable
                    ></el-input>
                  </div>
                </div>
              </el-col>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel_c">取 消</el-button>
        <el-button type="primary" @click="reset_c">重 置</el-button>
        <el-button type="primary" @click="create">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="补助信息(补助家庭)编辑"
      v-if="$route.path === '/info/subsidy-info'"
      width="35%"
      :show-close="false"
      :close-on-click-modal="false"
      :lock-scroll="true"
      :visible.sync="dialogFormVisible_house_edmit"
    >
      <el-form ref="form" :model="form" label-width="7.1rem" class="d-flex flex-column w-10">
        <el-col :span="24">
          <el-col :span="24" class="d-flex flex-column">
            <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
              <label for="date" class="el-form-item__label" style="width: 7.1rem;">村</label>
              <div class="el-form-item__content">
                <el-cascader
                  v-model="houseForm.SH_VillageidWrap"
                  :options="townToVillage"
                  :show-all-levels="false"
                  @change="get_typeAtt"
                  :disabled="this.admin.mType == 5"
                ></el-cascader>
              </div>
            </div>
            <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
              <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助项</label>
              <div class="el-form-item__content">
                <el-select v-model="houseForm.shEnjoythesubsidy" placeholder="请选择">
                  <el-option
                    v-for="item in createTypeAtt"
                    :key="item.S_Key"
                    :label="item.S_name"
                    :value="item.S_Key"
                  ></el-option>
                </el-select>
              </div>
            </div>
            <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
              <label for="date" class="el-form-item__label" style="width: 7.1rem;">家庭代表人姓名</label>
              <div class="el-form-item__content">
                <el-input v-model="houseForm.shName" placeholder="请输入内容"></el-input>
              </div>
            </div>
            <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
              <label for="date" class="el-form-item__label" style="width: 7.1rem;">代表人身份证号</label>
              <div class="el-form-item__content">
                <el-input v-model="houseForm.shBeiyong2" placeholder="请输入内容"></el-input>
              </div>
            </div>
            <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
              <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助年份</label>
              <div class="el-form-item__content">
                <el-date-picker
                  v-model="houseForm.shHu"
                  format="yyyy"
                  value-format="yyyy"
                  type="year"
                  placeholder="选择日期"
                ></el-date-picker>
              </div>
            </div>
            <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
              <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助金额</label>
              <div class="el-form-item__content">
                <el-input v-model="houseForm.shBeiyong3" placeholder="请输入内容"></el-input>
              </div>
            </div>
          </el-col>
          <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
            <label for="date" class="el-form-item__label" style="width: 7.1rem;">家庭地址</label>
            <div class="el-form-item__content">
              <el-input v-model="houseForm.shAddress" clearable></el-input>
            </div>
          </div>
          <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
            <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助原因</label>
            <div class="el-form-item__content">
              <el-input v-model="houseForm.shFamilyinformation" type="textarea" :rows="5" clearable></el-input>
            </div>
          </div>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible_house_edmit = false">取 消</el-button>
        <el-button type="primary" @click="updata_save_house">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="补助信息(补助对象)编辑"
      v-if="$route.path === '/info/subsidy-info'"
      width="35%"
      :show-close="false"
      :close-on-click-modal="false"
      :lock-scroll="true"
      :visible.sync="dialogFormVisible_object_edmit"
    >
      <el-form ref="form" :model="form" label-width="7.1rem" class="d-flex flex-column w-10">
        <el-col :span="24" class="d-flex flex-column">
          <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
            <label for="date" class="el-form-item__label" style="width: 7.1rem;">村</label>
            <div class="el-form-item__content">
              <el-cascader
                v-model="objectForm.soVillageidWrap"
                :options="townToVillage"
                :show-all-levels="false"
                @change="get_typeAtt"
                :disabled="this.admin.mType == 5"
              ></el-cascader>
            </div>
          </div>
          <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
            <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助项</label>
            <div class="el-form-item__content">
              <el-select v-model="objectForm.soEnjoythesubsidy" placeholder="请选择">
                <el-option
                  v-for="item in createTypeAtt"
                  :key="item.S_Key"
                  :label="item.S_name"
                  :value="item.S_Key"
                ></el-option>
              </el-select>
            </div>
          </div>
          <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
            <label for="date" class="el-form-item__label" style="width: 7.1rem;">对象名字</label>
            <div class="el-form-item__content">
              <el-input v-model="objectForm.soName" placeholder="请输入内容"></el-input>
            </div>
          </div>
          <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
            <label for="date" class="el-form-item__label" style="width: 7.1rem;">性别</label>
            <div class="el-form-item__content">
              <el-select v-model="objectForm.soBeiyong1" placeholder="请选择">
                <el-option v-for="item in ['男', '女']" :key="item" :label="item" :value="item"></el-option>
              </el-select>
            </div>
          </div>
          <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
            <label for="date" class="el-form-item__label" style="width: 7.1rem;">身份证号</label>
            <div class="el-form-item__content">
              <el-input v-model="objectForm.soShenfenzheng" placeholder="请输入内容"></el-input>
            </div>
          </div>
          <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
            <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助年份</label>
            <div class="el-form-item__content">
              <el-date-picker
                v-model="objectForm.soBeiyong5"
                format="yyyy"
                value-format="yyyy"
                type="year"
                placeholder="选择日期"
              ></el-date-picker>
            </div>
          </div>
          <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
            <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助金额</label>
            <div class="el-form-item__content">
              <el-input v-model="objectForm.soBeiyong2" placeholder="请输入内容"></el-input>
            </div>
          </div>
        </el-col>
        <div class="el-form-item el-form-item--medium mb-2 w-10 d-flex jc-start">
          <label for="date" class="el-form-item__label" style="width: 7.1rem;">补助原因</label>
          <div class="el-form-item__content">
            <el-input v-model="objectForm.soBeiyong4" type="textarea" :rows="5" clearable></el-input>
          </div>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible_object_edmit = false">取 消</el-button>
        <el-button type="primary" @click="updata_save_object">确 定</el-button>
      </div>
    </el-dialog>
  </el-row>
</template>

<script>
export default {
  data() {
    return {
      model: {},
      admin: {},
      obj: {},
      items: [
        //表格内容
      ],
      init_items: [
        //原始表格渲染数据
      ],
      pagination: {
        current_page: 1,
        page_sizes: [20, 30, 50, 100],
        page_size: 20,
        total: 0,
        page_length: 0
      },
      loading: true,
      formLabelWidth: "100px",
      form: {
        //弹出框内容
      },
      objectForm: {},
      houseForm: {},
      query: {
        // object: 0,
        quId: 1349,
        // zId: "",
        // vId: "",
        qType: 1,
        // name: ""
        villageWrap: []
      },
      //序列id
      index_id: 0,
      index: 0,
      //对应类型
      typeAtt: [],
      //对应上下政策
      upAtt: [],
      downAtt: [],
      //多删数组
      delAtt: [],
      multipleSelection: [],
      //增加url
      url: "/susbidyInformation/insertSubsidyType/",
      type_url: "/susbidyInformation/insertSubsidyType/",
      mes_url: "/susbidyInformation/insertSubsidyName/",
      //文件上传
      fileList: [],
      file_form: {},
      fileUrl: `ImportSubsidyProsonal/`,
      url_account: `ImportSubsidyProsonal/`,
      url_manage: `ImportSubsidyFamily/`,
      //上传类型
      type: 1,
      //删除的对象
      del_obj: {},
      delMany: {},
      //模态框
      dialogFormVisible_create: false,
      dialogFormVisible_edmit: false,
      dialogFormVisible_house_edmit: false,
      dialogFormVisible_object_edmit: false,
      villageMes: [],

      townToVillage: [
        {
          value: "",
          label: "",
          children: [
            {
              value: "",
              label: ""
            }
          ]
        }
      ],
      createTypeAtt: []
    };
  },

  methods: {
    async init() {
      // const  await get_villageMes()
      const town = await this.$http.get(`/caiwu/findzhenByRegionId/1349`);
      town.data.data.forEach(async (_town, i) => {
        _town.label = _town.zName;
        _town.value = _town.zhenId;
        const village = await this.$http.get(
          `/caiwu/findzhenByZhenId/${_town.zhenId}`
        );
        let att = [];
        village.data.data.forEach((_village, index) => {
          att.push({
            label: _village.vName,
            value: "$" + _village.villageId
          });
          if (
            i == town.data.data.length - 1 &&
            index == village.data.data.length - 1
          ) {
            // console.log(index)
            this.townToVillage = town.data.data;
            this.setQuery();
            this.to_query()
          }
        });
        _town.children = att;
      });
    },
    async get_villageMes() {
      const res = await this.$http.get("h/cacheVillage");
      this.villageMes = res.data.data;
    },
    setQuery() {
      // this.query.quId = this.admin.mRegion
      if (this.admin.mType == 4) {
        // this.query.mRegion = this.admin.mRegion;
        // this.get_townAtt();
        // this.query.mZhenid = this.admin.mZhenid;
        // this.get_villageAtt();
        delete this.query.quId;
        this.query.zId = this.admin.mZhenid;
        let att = [];
        this.townToVillage.forEach(item => {
          if (item.zhenId == this.admin.mZhenid) {
            att.push(item);
          }
        });
        this.townToVillage = att;
        this.query.villageWrap = [this.admin.mZhenid];
        this.selectTownOrVillage([this.admin.mZhenid]);
      }
      if (this.admin.mType == 5) {
        delete this.query.quId;
        // this.get_townAtt();
        this.query.zId = this.admin.mZhenid;
        // this.get_villageAtt();
        this.query.vId = this.admin.mVillageid;
        // this.get_typeAtt();
      }
    },
    setObj(obj) {
      obj.adminId = this.admin.managerId;
      (obj.startPage = this.pagination.current_page);
      obj.pageSize = this.pagination.page_size;
    },
    selectTownOrVillage(val) {
      this.query.zId = val[0];
      this.query.vId = val[1] ? parseInt(val[1].replace("$", "")) : "";
      // console.log(val);
    },
    //请求数据
    async fetch(obj) {
      this.loading = true;
      this.setObj(obj);
      const res = await this.$_http.post(
        `queryObjectDynamic`,
        this.Qs.stringify(obj)
        // { headers: { "Content-Type": "application/x-www-form-urlencoded" } }
      );
      this.init_items = res.data;
      this.items = res.data.data;
      this.up_pagination();
      if (
        this.$util.getCookie("current_page") !==
        String(this.pagination.current_page)
      ) {
        this.handleCurrentChange(this.$util.getCookie("current_page"));
      }
      if (res.status == 200) {
        this.loading = false;
      }
    },
    typeChange() {
      this.to_query();
    },
    handleSelectionChange(val) {
      let att = [];
      this.multipleSelection = val;
      this.multipleSelection.forEach(item => {
        if (this.query.qType == 1) {
          let { subsidyobjectId } = item;
          att.push(subsidyobjectId);
        } else {
          let { subsidizedhouseholdsId } = item;
          att.push(subsidizedhouseholdsId);
        }
      });
      this.delAtt = att;
    },
    get_delObj() {
      let { managerId } = this.admin;
      this.del_obj = { managerId };
    },
    get_delMany() {
      this.delMany = this.delAtt;
    },
    async delHouse(id, name) {
      this.$confirm(`此操作将永久删除 ${name}, 是否继续?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(async index => {
          const res = await this.$_http.post(
            `deleteObject`,
            this.Qs.stringify(
              {
                objectId: [id],
                managerId: this.admin.managerId,
                type: this.query.qType
              },
              { arrayFormat: "repeat" }
            )
          );
          if (res.status === 200) {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.to_query();
          } else {
            this.$message({
              type: "error",
              message: "删除失败!"
            });
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    async delObject(id, name) {
      this.$confirm(`此操作将永久删除 ${name}, 是否继续?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(async index => {
          const res = await this.$_http.delete(
            `deleteHolds/${id}/${this.admin.managerId}/1`
          );
          if (res.status === 200) {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.to_query();
          } else {
            this.$message({
              type: "error",
              message: "删除失败!"
            });
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    async updata(index, flag) {
      this.index_id = index;
      this.form = this.items[index];
      this.form.SI_beiyong2 = parseInt(this.form.SI_beiyong2);

      this.show_init();
      this.get_villageAtt(true);
      this.get_groupAtt(true);
      const res = await this.$http.get(
        `/susbidyInformation/queryDetailById/${this.form.SubsidyInformation_Id}`
      );
      setTimeout(() => {
        if (flag) {
          this.dialogFormVisible_all = true;
        } else {
          this.dialogFormVisible_edmit = true;
        }
      }, 200);
    },
    async updataHouse(index, flag) {
      this.index_id = index;
      let obj = {};
      obj = JSON.parse(JSON.stringify(this.items[index]));
      obj.SH_VillageidWrap = [
        this.getTownByVillage(obj.shVillageid),
        "$" + obj.shVillageid
      ];
      this.get_typeAtt([
        this.getTownByVillage(obj.shVillageid),
        "$" + obj.shVillageid
      ]);
      //去除不干净
      delete obj.village;
      delete obj.subsidyType;
      delete obj.subsidyname;

      obj.shEnjoythesubsidy = parseInt(obj.shEnjoythesubsidy);

      this.houseForm = Object.assign({}, obj);

      this.dialogFormVisible_house_edmit = true;
    },
    async updataObject(index, flag) {
      this.index_id = index;
      let obj = {};
      obj = JSON.parse(JSON.stringify(this.items[index]));
      obj.soVillageidWrap = [
        this.getTownByVillage(obj.soVillageid),
        "$" + obj.soVillageid
      ];
      this.get_typeAtt([
        this.getTownByVillage(obj.soVillageid),
        "$" + obj.soVillageid
      ]);
      //去除不干净
      delete obj.village;
      delete obj.subsidyType;
      delete obj.subsidyname;

      obj.soEnjoythesubsidy = parseInt(obj.soEnjoythesubsidy);

      this.objectForm = Object.assign({}, obj);

      this.dialogFormVisible_object_edmit = true;
    },
    getTownByVillage(villageId) {
      let townId = "";
      this.townToVillage.forEach(town => {
        town.children.forEach(
          item => item.value == villageId && [(townId = town.value)]
        );
      });
      return townId;
    },
    async updata_save_house() {
      this.houseForm.managerId = this.admin.managerId;
      const res = await this.$_http.post(
        `updateHolds`,
        this.Qs.stringify(this.houseForm)
      );
      if (res.status == 200) {
        this.$message({
          type: "success",
          message: `${res.data.status}`
        });
        this.to_query();
        this.dialogFormVisible_house_edmit = false;
      }
    },
    async updata_save_object() {
      this.objectForm.managerId = this.admin.managerId;
      const res = await this.$_http.post(
        `updateObject`,
        this.Qs.stringify(this.objectForm)
      );
      if (res.status == 200) {
        this.$message({
          type: "success",
          message: `${res.data.status}`
        });
        this.to_query();
        this.dialogFormVisible_object_edmit = false;
      }
    },
    async del_multip(name) {
      if (this.delAtt.length == 0) {
        return;
      }
      this.get_delMany();
      let str = "";
      this.multipleSelection.forEach(item => {
        str += item[name] + "\t\t";
      });
      console.log(this.delAtt);
      this.$confirm(`此操作将永久删除 , 是否继续?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(async index => {
          const res = await this.$_http.post(
            `deleteObject`,
            this.Qs.stringify(
              {
                objectId: this.delAtt,
                managerId: this.admin.managerId,
                type: this.query.qType
              },
              { arrayFormat: "repeat" }
            )
          );
          console.log(".....////");
          console.log(res);
          if (res.status === 200) {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.to_query();
          } else {
            this.$message({
              type: "error",
              message: "删除失败!"
            });
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    //分页功能
    up_pagination() {
      this.pagination.page_length = Math.ceil(
        this.init_items.count / this.pagination.current_page
      );
      this.pagination.total = this.init_items.count;
    },
    handleSizeChange(val) {
      this.pagination.page_size = val;
      this.to_query();
    },
    async handleCurrentChange(val) {
      this.pagination.current_page = val;
      this.$util.setCookie("current_page", this.pagination.current_page);
      this.to_query();
    },
    //query
    to_query() {
      let obj = JSON.parse(JSON.stringify(this.query));
      this.fetch(obj);
    },
    async get_typeAtt(val) {
      this.objectForm.soVillageid = parseInt(val[1].replace("$", ""));
      this.houseForm.shVillageid = parseInt(val[1].replace("$", ""));
      const res = await this.$http.get(
        `susbidyInformation/querySubsidyDynamic/1/1000/1349?zhenId=${
          val[0]
        }&cunId=${parseInt(val[1].replace("$", ""))}`
      );
      console.log(res.data.list.subsidyinformation);
      this.createTypeAtt = res.data.list.subsidyinformation;
    },
    //create
    reset_c() {
      this.$confirm("确定重置新增数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "info"
      }).then(() => {
        this.$message({
          type: "success",
          message: "已重置"
        });
        this.form = {};
      });
    },
    show_init() {
      switch (this.admin.mType) {
        case 2:
          // this.get_townAtt(true);
          break;
        case 3:
          break;
        case 4:
          // this.get_townAtt(true);
          // this.form.siBeiyong2 = this.admin.mZhenid;
          // this.get_villageAtt(true);
          break;
        case 5:
          this.objectForm.soVillageidWrap = [
            this.admin.mZhenid,
            "$" + this.admin.mVillageid
          ];
          this.houseForm.SH_VillageidWrap = [
            this.admin.mZhenid,
            "$" + this.admin.mVillageid
          ];
          // console.log([this.admin.mZhenid, '$' + this.admin.mVillageid]);
          this.get_typeAtt([this.admin.mZhenid, "$" + this.admin.mVillageid]);
          break;
      }
    },
    show_form() {
      this.clearObj(this.objectForm);
      this.clearObj(this.houseForm);
      this.show_init();
      this.dialogFormVisible_create = true;
    },
    set_form() {
      this.form.managerId = this.admin.managerId;

      let {
        SI_SubsidyAmount: siSubsidyamount,
        ST_Name,
        S_name: siNameofsubsidy,
        SubsidyInformation_Id: subsidyinformationId,
        siStandard,
        siReceivetime,
        siPrize,
        siThing,
        mVillageid: sBeiyong2
      } = this.form;
      Object.assign(this.form, {
        siSubsidyamount,
        siNameofsubsidy,
        subsidyinformationId,
        siStandard,
        siReceivetime,
        siPrize,
        siThing,
        sBeiyong2
      });
    },
    cancel_c() {
      this.$confirm("取消添加将不会保存该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "已取消！"
          });
          this.form = {};
          this.dialogFormVisible_create = false;
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消操作"
          });
        });
    },
    change_create(tab) {
      if (tab.label == "补助对象信息添加") {
        this.create = this.objectCreate;
      } else if (tab.label == "补助家庭信息添加") {
        this.create = this.houseCreate;
      }
    },
    success_c(res, file, files) {},
    async objectCreate() {
      this.objectForm.managerId = this.admin.managerId;
      const res = await this.$_http.post(
        `addObjectDynamic`,
        this.Qs.stringify(this.objectForm)
      );
      if (res.status == 200) {
        this.$message({
          type: "success",
          message: `${res.data.status}`
        });
        this.to_query();
        this.dialogFormVisible_create = false;
      }
    },
    async houseCreate() {
      this.houseForm.managerId = this.admin.managerId;
      const res = await this.$_http.post(
        `addHoldsDynamic`,
        this.Qs.stringify(this.houseForm)
      );
      if (res.status == 200) {
        this.$message({
          type: "success",
          message: `${res.data.status}`
        });
        this.to_query();
        this.dialogFormVisible_create = false;
      }
    },
    async create() {
      this.objectCreate();
    },
    reset_u() {
      this.$confirm("确定重置编辑数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "info"
      }).then(() => {
        this.$message({
          type: "success",
          message: "已重置"
        });
        for (let item in this.form) {
          if (item !== "_id") {
            this.form[item] = "";
          }
        }
      });
    },
    cancel_u() {
      this.$confirm("取消添加将不会保存该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "已取消！"
          });
          setTimeout(() => {
            this.dialogFormVisible_edmit = false;
          }, 200);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消操作"
          });
        });
    },
    async updata_save() {
      this.set_form();
      const res = await this.$http.put(
        `/susbidyInformation/updateSubsidyInformation/${this.admin.managerId}/${this.admin.mType}`,
        this.Qs.stringify(this.form)
      );
      if (res.status == 200) {
        this.dialogFormVisible_edmit = false;
        this.to_query();
        this.$message({
          message: "res.data.STSTUS",
          type: "success"
        });
      } else {
        this.$message({
          message: "编辑失败",
          type: "error"
        });
      }
    },
    cancel() {
      this.dialogFormVisible_all = false;
    },
    showAll(index) {
      this.updata(index, true);
    }
  },
  async created() {
    this.admin = this.$util.handleLocalStorage("get", "admin");
    this.pagination.current_page = 1;
    this.$util.setCookie("current_page", this.pagination.current_page);
    await this.init();
    this.fetch(this.query);
  }
};
</script>

<style lang="scss" scoped>
.query-form {
  padding-top: 20px;
  margin-bottom: 20px;
  background-color: #f2f2f2;
  display: flex;
  justify-content: flex-start;
}
.el-form--inline .el-form-item {
  display: inline-block;
  margin-right: 10px;
  vertical-align: top;
}
</style>

